
    <!DOCTYPE html>
    <html lang="zh-CN">
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>2、线程的实现 - 学习卡片</title>
      <style>
        body { font-family: sans-serif; background-color: #f0f8ff; color: #333; display: flex; flex-direction: column; align-items: center; padding: 50px 20px; }
        .header h1 { font-size: 32px; }
        .grid-container { display: grid; grid-template-columns: repeat(3, 1fr); gap: 28px; width: 100%; max-width: 1200px; }
        .card-container { perspective: 1200px; cursor: pointer; height: 250px; }
        .card { width: 100%; height: 100%; position: relative; transform-style: preserve-3d; transition: transform 0.7s; border-radius: 16px; box-shadow: 0 4px 16px rgba(0,0,0,0.08); }
        .card-container.flipped .card { transform: rotateY(180deg); }
        .card-face { position: absolute; width: 100%; height: 100%; backface-visibility: hidden; display: flex; flex-direction: column; box-sizing: border-box; border-radius: 16px; background-color: #fff; padding: 24px; }
        .card-back { background-color: #f0fff4; transform: rotateY(180deg); justify-content: space-between; }
        .card-category { font-size: 14px; color: #0052d9; margin-bottom: 8px; font-weight: 500; }
        .card-question { font-size: 20px; font-weight: 500; flex-grow: 1; display: flex; align-items: center; justify-content: center; text-align: center; }
        .card-answer-wrapper { flex-grow: 1; overflow-y: auto; }
        .card-answer { font-size: 15px; line-height: 1.7; }
        .card-footer { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 16px; margin-top: 16px; }
        .card-source { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 12px; margin-top: 12px; }
      </style>
    </head>
    <body>
      <div class="header">
        <h1>2、线程的实现 - 学习卡片</h1>
      </div>
      <div class="grid-container">
        
    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">概念</div>
          <div class="card-question">线程和进程在资源分配和内存共享方面有何根本区别？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">概念</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">进程是操作系统分配资源的最小单位，拥有独立的内存空间和数据；而线程是进程的子任务，共享进程的内存空间和资源。</div>
          </div>
          <div class="card-source">来源: 线程的基本概念 -> 线程与进程的区别</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">技术</div>
          <div class="card-question">在Java中，通过实现`Runnable`接口来创建线程需要哪些核心步骤？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">技术</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">核心步骤包括：1. 创建一个类实现`Runnable`接口并重写`run()`方法；2. 创建该`Runnable`实现类的实例；3. 将该实例作为参数传递给`Thread`类的构造方法来创建`Thread`对象；4. 调用`Thread`对象的`start()`方法启动线程。</div>
          </div>
          <div class="card-source">来源: 线程实现方式 -> 实现Runnable接口</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">特性</div>
          <div class="card-question">与`Runnable`接口相比，使用`Callable`接口定义线程任务有何主要优势？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">特性</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">主要优势在于`Callable`接口的`call()`方法可以返回一个执行结果，并且能够抛出异常。而`Runnable`的`run()`方法没有返回值。</div>
          </div>
          <div class="card-source">来源: 线程实现方式 -> 使用Callable和Future</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">一个Java线程从“新建状态”转换到“就绪状态”需要什么操作？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">当线程对象被创建后，它处于“新建状态（New）”。当调用该线程对象的`start()`方法后，线程就会进入“就绪状态（Runnable）”。</div>
          </div>
          <div class="card-source">来源: 线程的生命周期 -> 线程状态的转换</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">什么是线程同步？Java中实现同步的两种常见方法是什么？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">线程同步是指多个线程在访问共享资源时按照一定的顺序依次进行，以避免数据不一致。Java中可以通过使用`synchronized`关键字创建“同步代码块”和“同步方法”来实现。</div>
          </div>
          <div class="card-source">来源: 线程的同步与互斥 -> 同步（Synchronization）</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">技术</div>
          <div class="card-question">在线程通信中，`notify()`和`notifyAll()`方法在唤醒等待线程时有何不同？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">技术</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">`notify()`方法用于唤醒一个正在等待该对象锁的线程，若有多个则由系统决定唤醒哪一个。而`notifyAll()`方法则会唤醒所有正在等待该对象锁的线程。</div>
          </div>
          <div class="card-source">来源: 线程之间的通讯</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">模式</div>
          <div class="card-question">除了使用`synchronized`等同步机制，文档还提到了哪三种保障线程安全的方法？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">模式</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">文档还提到了三种方法：1. 使用线程安全的数据结构（如`ConcurrentHashMap`）；2. 使用不可变对象，因为其状态不能被修改；3. 使用`Atomic`类来保证操作的原子性。</div>
          </div>
          <div class="card-source">来源: 线程安全</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">理论</div>
          <div class="card-question">线程死锁产生的四个必要条件是什么？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">理论</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">线程死锁产生的四个必要条件是：互斥条件、请求与保持条件、不剥夺条件和循环等待条件。</div>
          </div>
          <div class="card-source">来源: 线程死锁 -> 线程死锁的原因</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">技术</div>
          <div class="card-question">文档中提出了哪四种解决线程死锁问题的策略？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">技术</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">四种解决方法策略是：1. 避免循环等待条件；2. 破坏不可抢占条件（允许线程主动释放资源）；3. 破坏持有并等待条件（要求线程一次性获取所有资源）；4. 设置超时等待。</div>
          </div>
          <div class="card-source">来源: 线程死锁 -> 线程死锁的解决方法</div>
        </div>
      </div>
    </div>

      </div>
    </body>
    </html>
